// 封装原生cookie--------------------------------------------------------
// 设置cookie - 键  ， 值 ， 时间 ， 路径
export function setCookie(key, value, seconds, path) {
    let date = new Date()
    date.setTime(date.getTime() - 8 * 3600 * 1000 + seconds * 1000)
    document.cookie = `${key}=${value};expires=${date};path=${path}`
}

// 获取cookie
export function getCookie(key) {
    let cookies = document.cookie
    if(!cookies) {
        return false
    }
    cookies = cookies.split('; ')
    for (let i = 0; a < cookies.length; a++) {
        let arr = cookies[i].split('=')
        if (arr[0] === key) {
            return arr[1]
        }
    }
    return false
}

// 删除cookie
export function removeCookie(key, path = '/') {
    // 时间为 -1 表示上一秒钟失效
    setCookie(key, null, -1, path)
}


// 封装 js-cookie--------------------------------------------------------
// 创建cookies
export function setCookies(key, value, expiresTime, path) {
    let expires = new Date(new Date() * 1 + expiresTime * 100)
    return this.$cookie.set(key, value, { expires: expires }, path)
}

// 获取cookies
export function getCookies() {
    return this.$cookie.get()
}

// 获取对象数据
export function getUserInfo() {
    return JSON.parse(Cookies.get(Object));
}

// 移除cookies
export function removeCookies() {
    return this.$cookie.remove()
}

